package com.huawei.bus.minitest;

import java.io.File;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.huawei.bus.minitest.constant.JSONConstant;
import com.huawei.bus.minitest.exe.ExecuteFactory;
import com.huawei.bus.minitest.exe.IExecute;
import com.huawei.bus.minitest.util.FileUtils;

public class TestCase {
	private String testsuiteName;
	private String name;
	private String desc;
	private String testcaseFilePath;
	private ArrayList<IExecute> steps;
	
	public TestCase() {
		super();
	}

	public TestCase(File file) throws JSONException {
		String str = FileUtils.readFileByChars(file);
		JSONObject jsObj = new JSONObject(str);
		name = jsObj.getString(JSONConstant.TEST_CASE_NAME);
		desc = jsObj.getString(JSONConstant.TEST_CASE_DESC);
		testcaseFilePath = file.getAbsolutePath();
		JSONArray jsArr = jsObj.getJSONArray("steps");
		if(jsArr != null && jsArr.length()>0)
		{
			steps = new ArrayList<IExecute>();
			for (int i = 0; i < jsArr.length(); i++) {
				JSONObject currentJsonObj = jsArr.getJSONObject(i);
				IExecute exe = ((ExecuteFactory) ExecuteFactory.getInstance()).getExecute(currentJsonObj);
				steps.add(exe);
			}
		}
	}
	
	public TestCase(File file,String tsName) throws JSONException{
		this(file);
		testsuiteName = tsName;
	}

	public ArrayList<IExecute> getSteps() {
		return steps;
	}

	public void setSteps(ArrayList<IExecute> steps) {
		this.steps = steps;
	}
}
